<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/11/28
 * Time: 18:34
 */

namespace app\api\model;


class Book extends BaseModel
{
    protected $hidden = ['img_id', 'from', 'category_id', 'pivot', 'create_time', 'delete_time', 'update_time'];

    public function getMainImgUrlAttr($value, $data)
    {
        return $this->getWholeUrl($value, $data);
    }

    public static function getBookList($size,$page){
        // return self::order('create_time desc')->paginate($size,true,['page'=>$page]);

        return self::order('id desc')->paginate($size,true,['page'=>$page]);
    }

    public static function getBookByID($id)
    {
        return self::where('id','=',$id)->find();
    }

    public static function getBookByISBN($isbn)
    {
        return self::where('isbn','=',$isbn)->find();
    }

    // public static function getNewBooks($num){
    //     return self::limit($num)->order('create_time desc')->select();
    // }

    public static function getByCategory($category){
        return self::where('category_id','=',$category)->order('create_time desc')->select();
    }

    // public static function getNewInCategory($id,$num){
    //     return self::where('category_id','=',$id)->limit($num)->order('create_time desc')->select();
    // }
}